local joy__wuji = fk.CreateSkill {

  name = "joy__wuji",

  tags = { Skill.Wake, },

}



joy__wuji:addEffect(fk.EventPhaseStart, {
  name = "joy__wuji",
  anim_type = "special",
  events = {fk.EventPhaseStart},
  frequency = Skill.Wake,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(joy__wuji.name) and player.phase == Player.Finish and player:usedSkillTimes(joy__wuji.name, Player.HistoryGame) == 0
  end,
  can_wake = function(self, event, target, player, data)
    local n = 0
    player.room.logic:getActualDamageEvents( 1, function(e)
      local damage = e.data[1]
      n = n + damage.damage
      if n > 2 then return true end
    end)
    return n > 2
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:changeMaxHp(player, 1)
    if player:isWounded() and not player.dead then
      room:recover({ who = player, num = 1, recoverBy = player, skillName = joy__wuji.name })
    end
    if player.dead then return end
    for _, id in ipairs(Fk:getAllCardIds()) do
      if Fk:getCardById(id).name == "blade" then
        if room:getCardArea(id) == Card.DrawPile or room:getCardArea(id) == Card.DiscardPile or room:getCardArea(id) == Card.PlayerEquip then
          room:moveCardTo(id, Card.PlayerHand, player, fk.ReasonPrey, joy__wuji.name)
          break
        end
      end
    end
  end,
})

return joy__wuji